home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / What's New? / Software Development Kits / Mac OS USB DDK / MacOS USB DDK 1.0b4 / NeptuneDDK / Examples / SerialBox / ShimSerialUtils.c < prev   
Encoding:
C/C++ Source or Header  |  1998-06-26  |  3.4 KB  |  160 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ShimSerialUtils.c
  3.  
  4.     Contains:    Utility routines 
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1996-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.  
  11. */
  12.  
  13. #include "ShimSerialInternal.h"
  14.  
  15. void *
  16. GetDeviceProperty(    const RegEntryID *        deviceEntry,
  17.                     const RegPropertyName *    propertyName,
  18.                     RegPropertyValueSize *    propertySize)
  19.     {
  20.     OSStatus    status;
  21.     void *        propertyBuffer = NULL;
  22.  
  23.     
  24.     SysDebugStr("\pGetDeviceProperty() entered !");
  25.  
  26.     
  27.     status = RegistryPropertyGetSize(deviceEntry,propertyName,propertySize);
  28.     if (status == noErr)
  29.         {
  30.         propertyBuffer = PoolAllocateResident(*propertySize,true);
  31.         if (propertyBuffer)
  32.             status = RegistryPropertyGet(deviceEntry,propertyName,propertyBuffer,propertySize);
  33.         }
  34.     
  35.     if (status != noErr)
  36.         propertyBuffer = NULL;
  37.     
  38.     return propertyBuffer;
  39.     }
  40.  
  41. void
  42. DisposeDeviceProperty(void * propertyToDispose)
  43.     {
  44.     SysDebugStr("\pDisposeDeviceProperty() entered !");
  45.     if (propertyToDispose)
  46.         PoolDeallocate(propertyToDispose);
  47.     }
  48.  
  49.  
  50.  
  51. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  52.  * DoOpenSession
  53.  *
  54.  * Process an OpenDriver request to the stub drivers.
  55.  */
  56. OSStatus DoOpenSession(ParmBlkPtr pb)
  57. {
  58.     OSStatus    err;
  59. #pragma unused (pb)
  60.     
  61.     
  62.     // only allow one open session
  63.     
  64.     if (gGlobals->openSession)
  65.         return openErr;
  66.         
  67.     //    reset internal indexes, buffers, etc.
  68.     
  69.     err = B_SetBuffer(gGlobals, nil, 0);
  70.     if (err)
  71.         return err;
  72.     
  73.     //  since we've cleared the buffer to zero initially we have to explicitly
  74.     //  initialize the baudRate, otherwise B_SetBaudRate will do a zero divide
  75.     
  76.     gGlobals->baudRate = kMaxBaudRate;            // <-- is this the right/reasonable value?
  77.                                                 // we can get the baud rate from the GET_CAPS function as well
  78.     gGlobals->UARTCrystalSpeed     = 3686400;      // should get this from the device capabilities
  79. //    gGlobals->UARTCrystalSpeed     = 1843200;      // should get this from the device capabilities
  80.     
  81.     //    reset default values for other variables
  82.  
  83.     gGlobals->lenParStop = kLen8Bits + kParNone + kStop1Bit;
  84.     gGlobals->xOnOffChar = 0;
  85.     gGlobals->peChar = 0;
  86.     gGlobals->peAltChar = 0;
  87.  
  88.     //    reset handshake default values as per scc serial driver
  89.  
  90.     gGlobals->serShk.fXOn = 0;
  91.     gGlobals->serShk.fCTS = 1;
  92.     gGlobals->serShk.xOn = 0;
  93.     gGlobals->serShk.xOff = 0;
  94.     gGlobals->serShk.errs = parityErr | hwOverrunErr | framingErr;
  95.     gGlobals->serShk.evts = 0;
  96.     gGlobals->serShk.fInX = 0;
  97.     gGlobals->serShk.fDTR = 1;
  98.  
  99.     //    reset serial status record
  100.  
  101.     gGlobals->serStat.cumErrs = 0;
  102.     gGlobals->serStat.xOffSent = 0;
  103.     gGlobals->serStat.rdPend = 0;
  104.     gGlobals->serStat.wrPend = 0;
  105.     gGlobals->serStat.ctsHold = 0;
  106.     gGlobals->serStat.xOffHold = 0;
  107.     
  108.     
  109.     
  110.     //    now turn on modem interrupts
  111.     
  112.     B_EnableSerialDevice(gGlobals);
  113.     
  114.     // we now have an open session
  115.     
  116.     gGlobals->openSession = true;
  117.     
  118.     
  119.     return noErr;
  120. }
  121.  
  122.  
  123.  
  124.  
  125.  
  126. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  127.  * DoCloseSession
  128.  *
  129.  * Process an CloseDriver request to the stub drivers.
  130.  */
  131. OSStatus DoCloseSession(ParmBlkPtr pb)
  132. {
  133. #pragma unused (pb)
  134.     
  135.     
  136.     if (gGlobals && gGlobals->openSession)
  137.     {
  138.     
  139.         //    now turn off interrupts on the card
  140.     
  141.         B_DisableSerialDevice(gGlobals);
  142.     
  143.         
  144.         
  145.         //    reset internal indexes, buffers, etc. - this
  146.         //    is important for vm to unhold memory on any
  147.         //    buffer the client may have requested earlier
  148.     
  149.         B_SetBuffer(gGlobals, nil, 0);
  150.             
  151.         
  152.         // we no longer have an open session
  153.         
  154.         gGlobals->openSession = false;
  155.     }
  156.     
  157.     return noErr;
  158. }
  159.  
  160.